package com.splant.android.smart.UILevel.Community.fragments;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.splant.android.R;
import com.splant.android.smart.ModelLevel.WaterListBean;
import com.splant.android.smart.SystemDefinedLevel.LRecyclerview.base.BaseMultiAdapter;
import com.splant.android.smart.SystemDefinedLevel.LRecyclerview.base.SuperViewHolder;
import com.splant.android.smart.UILevel.Utils.sPlantUitl;

/**
 * Created by Administrator on 2017/8/17.
 */

public class Garden_WaterList_Devices_Adapter extends BaseMultiAdapter<WaterListBean.Water> {

    public Garden_WaterList_Devices_Adapter(Context context) {
        super(context);
        addItemType(0, R.layout.garden_waterlist_device_item);

    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {

        ImageView img_water=holder.getView(R.id.img_water);
        TextView tv_waterId=holder.getView(R.id.tv_waterId);
        TextView tv_waterName=holder.getView(R.id.tv_waterName);
        TextView tv_waterState=holder.getView(R.id.tv_waterState);
        TextView tv_waterStartTime=holder.getView(R.id.tv_waterStartTime);
        TextView tv_waterEndTime=holder.getView(R.id.tv_waterEndTime);
        ImageView img_electricity=holder.getView(R.id.img_electricity);
        TextView tv_waterDbm=holder.getView(R.id.tv_waterDbm);

        WaterListBean.Water water=getDataList().get(position);

        int deviceType= sPlantUitl.getWaterType(water.getWaterId());

        if (deviceType==1)
        {
            if (water.getWaterState()==1)
                img_water.setImageResource(R.mipmap.garden_ic_water1_online);
            else
                img_water.setImageResource(R.mipmap.garden_ic_water1_offline);

        }
        else if (deviceType==2)
        {
            if (water.getWaterState()==1)
                img_water.setImageResource(R.mipmap.garden_ic_water2_online);
            else
                img_water.setImageResource(R.mipmap.garden_ic_water2_offline);
        }
        else
        {
            if (water.getWaterState()==1)
               img_water.setImageResource(R.mipmap.garden_ic_water3_online);
            else
                img_water.setImageResource(R.mipmap.garden_ic_water3_offline);
        }

        tv_waterId.setText(water.getWaterId());
        tv_waterName.setText(water.getWaterName());

        if (water.getWaterState()==1)
            tv_waterState.setText("在线");
        else if (water.getWaterState()==2)
            tv_waterState.setText("离线");
        else if (water.getWaterState()==3)
            tv_waterState.setText("未组网");

        tv_waterStartTime.setText(water.getStOnLine());
        tv_waterEndTime.setText(water.getEtOnLine());

        if (water.getElectricity()<0)
            water.setElectricity(0);

        if (water.getElectricity()<=25)
        {
            img_electricity.setImageResource(R.mipmap.garden_ic_electricity_1);
        }
        else if (water.getElectricity()<=50)
        {
            img_electricity.setImageResource(R.mipmap.garden_ic_electricity_2);
        }
        else if (water.getElectricity()<=75)
        {
            img_electricity.setImageResource(R.mipmap.garden_ic_electricity_3);
        }
        else
        {
            img_electricity.setImageResource(R.mipmap.garden_ic_electricity_4);
        }

        tv_waterDbm.setText(String.valueOf(water.getSignalIntensity()));


    }
}
